package com.ggy.ggyaiagent.rag;

import lombok.extern.slf4j.Slf4j;

import org.springframework.ai.chat.client.advisor.api.Advisor;
import org.springframework.ai.rag.advisor.RetrievalAugmentationAdvisor;
import org.springframework.ai.rag.generation.augmentation.ContextualQueryAugmenter;
import org.springframework.ai.rag.retrieval.search.VectorStoreDocumentRetriever;
import org.springframework.ai.vectorstore.VectorStore;
import org.springframework.ai.vectorstore.filter.Filter;
import org.springframework.ai.vectorstore.filter.FilterExpressionBuilder;

/**
 * 向量检索，的条件检索
 */
@Slf4j
public class LoveAppRagCustomAdvisorFactory {

    public static Advisor createLoveAppRagCustomAdvisor(VectorStore vectorStore,String status){
        Filter.Expression expression = new FilterExpressionBuilder()
                .eq("status", status).build();
        VectorStoreDocumentRetriever documentRetriever = VectorStoreDocumentRetriever.builder()
                .vectorStore(vectorStore)
                .filterExpression(expression)//过滤条件
                .similarityThreshold(0.5)//相似度阈值
                .topK(3)//返回文档数量
                .build();
        return RetrievalAugmentationAdvisor//寻回查询增加顾问
                .builder()
                .queryAugmenter(
                        LoveAppContextualQueryAugmenterFactory.createInstance()//空上下文处理
                )
                .documentRetriever(documentRetriever).build();
    }
}





















